package com.base.cn.platform.os.controller.mobile.classes.topic;

import com.base.cn.platform.os.common.MobileBaseController;
import com.base.cn.platform.os.service.course.classes.topic.reply.ClassesTopicReplyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import java.math.BigDecimal;
import java.util.Map;


/**
 * H5班级话题回复Controller
 *
 * @author zsw
 * @create 2018/7/5
 */
@Controller
@RequestMapping("/mobile/uc/class/topic")
public class MobileClassTopicReplyController extends MobileBaseController {

    @Autowired
    private ClassesTopicReplyService classesTopicReplyService;

    /**
     * 提交评论
     *
     * @param reply 评论
     */
    @RequestMapping("/ajax/save/reply")
    @ResponseBody
    public Map<String, Object> saveClassTopicReply(HttpServletRequest request,
                                                   @RequestBody Map<String, Object> reply) {
        BigDecimal userId = webMobileLoginUtil.getLoginUserId(request);
        reply.put("userId", userId);
        return classesTopicReplyService.saveClassesTopicReply(reply, true);
    }

    /**
     * 全部回复弹窗页
     *
     * @param params 参数
     */
    @RequestMapping("/ajax/all/reply")
    public String toReplySubReplyAll(Model model,
                                     @RequestBody Map<String, Object> params,@RequestParam(value = "currentPage", required = false, defaultValue = "1") int currentPage) {
        Map<String, Object> reply = classesTopicReplyService.findClassesTopicReplyListPage(params, currentPage, 10, true, false, true,true);
        model.addAttribute("reply", reply);
        return resultPage("/class/topic/reply/ajax-all-topic-reply");
    }

}
